var reviveCount = -100;
var mapIds = [];
var 准备地图 = 951000000;
var eventName = "怪物公园_重制版";

function init() {}

function setup(d, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var d = em.newInstance(eventName);
    for (var c = 952000000; c <= 952050000; c += 10000) {
        for (var b = 0; b <= 5; b++) {
            var e = d.setInstanceMap(c + b * 100);
            mapIds.push(c + b * 100);
            e.resetFully()
        }
    }
    for (var c = 953000000; c <= 953090000; c += 10000) {
        for (var b = 0; b <= 5; b++) {
            var e = d.setInstanceMap(c + b * 100);
            mapIds.push(c + b * 100);
            e.resetFully()
        }
    }
    for (var c = 954000000; c <= 954080000; c += 10000) {
        for (var b = 0; b <= 5; b++) {
            var e = d.setInstanceMap(c + b * 100);
            mapIds.push(c + b * 100);
            e.resetFully()
        }
    }
    return d
}

function onPlayerRegistered(e, d) {
    var f = d.getAPI().getNumberFromQuestCustomData(7901);
    var b = d.getAPI().getNumberFromQuestCustomData(7902);
    var c = 952000000 + f * 1000000 + b * 10000;
    for (var a = 0; a <= 5; a++) {
        var g = e.getMapInstance(c + a * 100);
        g.resetFully()
    }
    var g = e.getMapInstance(c);
    d.changeMap(g, g.getPortal(0));
    e.startEventTimer(1000 * 60 * 10)
}

function onPlayerRevived(b, a) {
    return false
}

function onMonsterKilled(b, e) {
    var c = player.getAPI().getNumberFromQuestCustomData(7901);
    var a = player.getAPI().getNumberFromQuestCustomData(7902);
    var f = Math.floor(player.getMapId() % 1000 / 100) + 1;
    var d = (c * 10 + a + 1) * f * player.getLevel() * 128;
    var g = player.getAPI().addNumberForQuestInfo(15180, "exp", d);
    player.getMap().startSimpleMapEffect("经验值奖励 " + player.getAPI().formatNumberWithComma(g) + " 累积！", 5120162);
    if (player.getMap().getNumMonsters() == 0) {
        player.getAPI().fieldEffect_ScreenMsg("monsterPark/clearF");
        player.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100)
    }
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 302050100:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 302050200:
            initProp("stage" + 1 + "_kill", 0);
            break;
        case 302050300:
            initProp("stage" + 1 + "_kill", 0);
            if (b.getJob() / 100 == 131) {
                if (b.isQuestFinished(100565)) {
                    if (b.getAPI().isQuestActive(100572)) {
                        b.forceCompleteQuest(100572)
                    }
                }
            }
            break
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(d, c, a) {
    var e = c.getAPI().getNumberFromQuestCustomData(7901);
    var b = c.getAPI().getNumberFromQuestCustomData(7902);
    em.setProperty("state_" + e + "_" + b, 0);
    d.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    d.unregisterPlayer(c)
};